package zhuyun.code

import java.util.*
import kotlin.coroutines.experimental.coroutineContext


fun main(args:Array<String>){
    val concreteComponent = ConcreteComponent()
    val concreteDecorator1 = ConcreteDecorator1(concreteComponent)
    concreteDecorator1.operation()
    val concreteDecorator2 = ConcreteDecorator2(concreteComponent)
    concreteDecorator2.operation()

}
interface Component{
    fun operation()
}
class ConcreteComponent:Component{
    override fun operation() {
        println("我是构建的原有功能")
    }

}
open class Decorator(open val component: Component):Component{
    override fun operation() {
        component.operation()
    }
}
class ConcreteDecorator1(override val component: Component):Decorator(component){
    fun addedFunction(){
        println("我是装饰1的额外功能")
    }

    override fun operation() {
        super.operation()
        addedFunction()
    }

}
class ConcreteDecorator2(override val component: Component):Decorator(component){
    fun addedFunction(){
        println("我是装饰2的额外功能")
    }
    override fun operation() {
        super.operation()
        addedFunction()
    }
}
